/**
 * Copyright 2018-2021 Streamlit Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

// stylelint-disable at-rule-no-vendor-prefix, declaration-no-important, selector-no-qualifying-type, property-no-vendor-prefi
@import "variables";
@import "vendor/rfs.scss";

// These variables are needed for reboot. We supply them from bootstrap's
// variable files
$font-size-root: null !default;
$font-family-base: $font-family-sans-serif !default;
$font-family-code: $font-family-monospace !default;
$body-bg: $white !default;
$body-color: $gray-900 !default;
$body-text-align: null !default;
$text-muted: $gray-600 !default;
$border-width: 1px !default;
$font-weight-normal: 400 !default;
$font-weight-bold: 700 !default;
$font-weight-bolder: bolder !default;
$font-weight-base: $font-weight-normal !default;
$hr-color: inherit !default;
$hr-height: $border-width !default;
$hr-opacity: 0.25 !default;
$headings-font-family: null !default;
$headings-font-style: null !default;
$headings-color: null !default;
$small-font-size: 0.875em !default;
$mark-padding: 0.2em !default;
$mark-bg: #fcf8e3 !default;
$sub-sup-font-size: 0.75em !default;
$link-color: $primary !default;
$link-decoration: underline !default;
$link-hover-color: darken($link-color, 15%) !default;
$link-hover-decoration: null !default;
$code-font-size: $small-font-size !default;
$kbd-padding-y: 0.2rem !default;
$kbd-padding-x: 0.4rem !default;
$kbd-font-size: $code-font-size !default;
$enable-rounded: true !default;
$nested-kbd-font-weight: $font-weight-bold !default;
$table-cell-padding-y: 0.5rem !default;
$table-caption-color: $text-muted !default;
$table-th-font-weight: null !default;
$enable-button-pointers: true !default;
$legend-margin-bottom: 0.5rem !default;
$legend-font-size: 1.5rem !default;
$legend-font-weight: null !default;
$grid-breakpoints: (
  xs: 0,
  sm: 576px,
  md: 768px,
  lg: 992px,
  xl: 1200px,
  xxl: 1400px,
) !default;

@function valid-radius($radius) {
  $return: ();
  @each $value in $radius {
    @if type-of($value) == number {
      $return: append($return, max($value, 0));
    } @else {
      $return: append($return, $value);
    }
  }
  @return $return;
}

@mixin border-radius($radius: $border-radius, $fallback-border-radius: false) {
  @if $enable-rounded {
    border-radius: valid-radius($radius);
  } @else if $fallback-border-radius != false {
    border-radius: $fallback-border-radius;
  }
}

// Maximum breakpoint width.
// The maximum value is reduced by 0.02px to work around the limitations of
// `min-` and `max-` prefixes and viewports with fractional widths.
// See https://www.w3.org/TR/mediaqueries-4/#mq-min-max
// Uses 0.02px rather than 0.01px to work around a current rounding bug in Safari.
// See https://bugs.webkit.org/show_bug.cgi?id=178261
//
//    >> breakpoint-max(md, (xs: 0, sm: 576px, md: 768px, lg: 992px, xl: 1200px))
//    767.98px
@function breakpoint-max($name, $breakpoints: $grid-breakpoints) {
  $max: map-get($breakpoints, $name);
  @return if($max and $max > 0, $max - 0.02, null);
}

// Media of at most the maximum breakpoint width. No query for the largest breakpoint.
// Makes the @content apply to the given breakpoint and narrower.
@mixin media-breakpoint-down($name, $breakpoints: $grid-breakpoints) {
  $max: breakpoint-max($name, $breakpoints);
  @if $max {
    @media (max-width: $max) {
      @content;
    }
  } @else {
    @content;
  }
}

// Reboot
//
// Normalization of HTML elements, manually forked from Normalize.css to remove
// styles targeting irrelevant browsers while applying new styles.
//
// Normalize is licensed MIT. https://github.com/necolas/normalize.css

// Document
//
// Change from `box-sizing: content-box` so that `width` is not affected by `padding` or `border`.

*,
*::before,
*::after {
  box-sizing: border-box;
}

// Root
//
// Ability to the value of the root font sizes, affecting the value of `rem`.
// null by default, thus nothing is generated.

:root {
  font-size: $font-size-root;
}

// Body
//
// 1. Remove the margin in all browsers.
// 2. As a best practice, apply a default `background-color`.
// 3. Prevent adjustments of font size after orientation changes in iOS.
// 4. Change the default tap highlight to be completely transparent in iOS.

body {
  margin: 0; // 1
  font-family: $font-family-base;
  @include font-size($font-size-base);
  font-weight: $font-weight-base;
  line-height: $line-height-base;
  color: $body-color;
  text-align: $body-text-align;
  background-color: $body-bg; // 2
  -webkit-text-size-adjust: 100%; // 3
  -webkit-tap-highlight-color: rgba($black, 0); // 4
}

// Future-proof rule: in browsers that support :focus-visible, suppress the focus outline
// on elements that programmatically receive focus but wouldn't normally show a visible
// focus outline. In general, this would mean that the outline is only applied if the
// interaction that led to the element receiving programmatic focus was a keyboard interaction,
// or the browser has somehow determined that the user is primarily a keyboard user and/or
// wants focus outlines to always be presented.
// See https://developer.mozilla.org/en-US/docs/Web/CSS/:focus-visible
// and https://developer.paciellogroup.com/blog/2018/03/focus-visible-and-backwards-compatibility/

[tabindex="-1"]:focus:not(:focus-visible) {
  outline: 0 !important;
}

// Content grouping
//
// 1. Reset Firefox's gray color
// 2. Set correct height and prevent the `size` attribute to make the `hr` look like an input field

hr {
  margin: 2em 0;
  padding: 0;
  color: $hr-color; // 1
  background-color: transparent;
  border: none;
  border-bottom: 1px solid $gray-light;
  opacity: $hr-opacity;
}

hr:not([size]) {
  height: $hr-height; // 2
}

h1 {
  font-weight: 700;
  font-family: $headings-font-family;
  font-style: $headings-font-style;
  font-weight: 700;
  color: $headings-color;

  // Use rem so we can remove it when first child, knowing that the
  // element-container above always adds 1rem.
  margin: 1.5rem 0 0.5rem 0;
  // Set padding in em-units to give it some adjustment that is proportional
  // to font size.
  padding: 0.5em 0 0.25em;
  // Set to 1 so it looks nice when wrapped.
  line-height: 1;

  @include font-size(2.25rem);
}

h2 {
  font-family: $headings-font-family;
  font-style: $headings-font-style;
  font-weight: 400;
  color: $headings-color;
  // Use rem so we can remove it when first child, knowing that the
  // element-container above always adds 1rem.
  margin: 1.5rem 0 0.5rem 0;
  // Set padding in em-units to give it some adjustment that is proportional
  // to font size.
  padding: 0.5em 0 0.25em;
  // Set to 1 so it looks nice when wrapped.
  line-height: 1;
  @include font-size(1.75rem);
}

h3 {
  font-family: $headings-font-family;
  font-style: $headings-font-style;
  font-weight: 500;
  color: $headings-color;
  @include font-size(1.25rem);
  // Use rem so we can remove it when first child, knowing that the
  // element-container above always adds 1rem.
  margin: 1.5rem 0 0.5rem 0;
  // Set padding in em-units to give it some adjustment that is proportional
  // to font size.
  padding: 0.5em 0 0.25em;
  // Set to 1 so it looks nice when wrapped.
  line-height: 1;
}

h4 {
  font-family: $headings-font-family;
  font-style: $headings-font-style;
  font-weight: 600;
  color: $headings-color;
  @include font-size(1rem);
  margin: 1rem 0 0 0;
  padding: 0.5em 0 0.25em;
  line-height: 1;
}

h5 {
  font-family: $headings-font-family;
  font-style: $headings-font-style;
  font-weight: 900;
  color: $headings-color;
  @include font-size(0.8rem);
  margin: 1rem 0 0 0;
  padding: 0.5em 0 0.25em;
  line-height: 1;
}

h6 {
  font-family: $headings-font-family;
  font-style: $headings-font-style;
  font-weight: 300;
  color: $headings-color;
  @include font-size(0.8rem);
  margin: 1rem 0 0 0;
  padding: 0.5em 0 0.25em;
  line-height: 1;
}

h1:first-child,
h2:first-child,
h3:first-child {
  margin-top: 0.5rem;
}

h4:first-child,
h5:first-child,
h6:first-child {
  margin-top: 0;
}

// Abbreviations
//
// 1. Duplicate behavior to the data-* attribute for our tooltip plugin
// 2. Add the correct text decoration in Chrome, Edge, Opera, and Safari.
// 3. Add explicit cursor to indicate changed behavior.
// 4. Prevent the text-decoration to be skipped.

abbr[title],
abbr[data-original-title] {
  // 1
  text-decoration: underline; // 2
  text-decoration: underline dotted; // 2
  cursor: help; // 3
  text-decoration-skip-ink: none; // 4
}

// Address

address {
  margin-bottom: 1rem;
  font-style: normal;
  line-height: inherit;
}

// Lists
// Reset margins on paragraphs
//
// Similarly, the top margin on `<p>`s get reset. However, we also reset the
// bottom margin to use `rem` units instead of `em`.
p,
ol,
ul,
dl {
  margin: 0 0 1rem 0;
  padding: 0;
  font-size: 1rem;
  font-weight: 400;
}

ol ol,
ul ul,
ol ul,
ul ol {
  margin-bottom: 0;
}

dt {
  font-size: 1rem;
  font-weight: 600;
  margin: 1em 0 0.2em 0;
  padding: 0;
}

// 1. Undo browser default

dd {
  margin: 0 0 0.2em 1.2em;
  font-size: 1rem;
}

// Strong
//
// Add the correct font weight in Chrome, Edge, and Safari

b,
strong {
  font-weight: $font-weight-bolder;
}

// Small
//
// Add the correct font size in all browsers

small {
  @include font-size($small-font-size);
}

// Mark

mark {
  padding: $mark-padding;
  background-color: $mark-bg;
}

// Sub and Sup
//
// Prevent `sub` and `sup` elements from affecting the line height in
// all browsers.

sub,
sup {
  position: relative;
  @include font-size($sub-sup-font-size);
  line-height: 0;
  vertical-align: baseline;
}

sub {
  bottom: -0.25em;
}
sup {
  top: -0.5em;
}

// Links

a {
  color: $link-color;
  text-decoration: $link-decoration;

  &:hover {
    color: $link-hover-color;
    text-decoration: $link-hover-decoration;
  }
}

// And undo these styles for placeholder links/named anchors (without href).
// It would be more straightforward to just use a[href] in previous block, but that
// causes specificity issues in many other styles that are too complex to fix.
// See https://github.com/twbs/bootstrap/issues/19402

a:not([href]):not([class]) {
  &,
  &:hover {
    color: inherit;
    text-decoration: none;
  }
}

// Code

pre,
code,
kbd {
  font-family: $font-family-code;
  @include font-size(1em); // Correct the odd `em` font sizing in all browsers.
}

samp {
  font-family: $font-family-code;
}

// Blockquote
samp,
blockquote {
  margin: 1em 0 1em -1px;
  padding: 0 0 0 1.2em;
  font-size: 1rem;
  border-left: 1px solid $gray-light;
}

// 1. Remove browser default top margin
// 2. Reset browser default of `1em` to use `rem`s
// 3. Don't allow content to break outside
// 4. Disable auto-hiding scrollbar in legacy Edge to avoid overlap,
//    making it impossible to interact with the content

pre {
  display: block;
  margin-top: 0; // 1
  margin-bottom: 1rem; // 2
  overflow: auto; // 3
  @include font-size($code-font-size);
  color: $pre-color;
  -ms-overflow-style: scrollbar; // 4

  // Account for some code outputs that place code tags in pre tags
  code {
    @include font-size(inherit);
    color: inherit;
    word-break: normal;
  }
}

code {
  @include font-size($code-font-size);
  color: $code-color;
  word-wrap: break-word;

  // Streamline the style when inside anchors to avoid broken underline and more
  a > & {
    color: inherit;
  }
}

kbd {
  padding: $kbd-padding-y $kbd-padding-x;
  @include font-size($kbd-font-size);
  color: $kbd-color;
  background-color: $kbd-bg;
  @include border-radius($border-radius-sm);

  kbd {
    padding: 0;
    @include font-size(1em);
    font-weight: $nested-kbd-font-weight;
  }
}

// Figures
//
// Apply a consistent margin strategy (matches our type styles).

figure {
  margin: 0 0 1rem;
}

// Images and content

img,
svg {
  vertical-align: middle;
}

// Tables
//
// Prevent double borders

table {
  caption-side: bottom;
  border-collapse: collapse;
}

caption {
  padding-top: $table-cell-padding-y;
  padding-bottom: $table-cell-padding-y;
  color: $table-caption-color;
  text-align: left;
}

// 1. Removes font-weight bold by inheriting
// 2. Matches default `<td>` alignment by inheriting `text-align`.
// 3. Fix alignment for Safari

th {
  font-weight: $table-th-font-weight; // 1
  text-align: inherit; // 2
  text-align: -webkit-match-parent; // 3
}

thead,
tbody,
tfoot,
tr,
td,
th {
  border-color: inherit;
  border-style: solid;
  border-width: 0;
}

// Forms
//
// 1. Allow labels to use `margin` for spacing.

label {
  display: inline-block; // 1
}

// Remove the default `border-radius` that macOS Chrome adds.
// See https://github.com/twbs/bootstrap/issues/24093

button {
  // stylelint-disable-next-line property-blacklist
  border-radius: 0;
}

// Work around a Firefox bug where the transparent `button` background
// results in a loss of the default `button` focus styles.
// Credit https://github.com/suitcss/base/

button:focus {
  outline: 1px dotted;
  outline: 5px auto -webkit-focus-ring-color;
}

// 1. Remove the margin in Firefox and Safari

input,
button,
select,
optgroup,
textarea {
  margin: 0; // 1
  font-family: inherit;
  @include font-size(inherit);
  line-height: inherit;
}

// Show the overflow in Edge

button,
input {
  overflow: visible;
}

// Remove the inheritance of text transform in Firefox

button,
select {
  text-transform: none;
}

// Set the cursor for non-`<button>` buttons
//
// Details at https://github.com/twbs/bootstrap/pull/30562
[role="button"] {
  cursor: pointer;
}

// Remove the inheritance of word-wrap in Safari.
// See https://github.com/twbs/bootstrap/issues/24990

select {
  word-wrap: normal;
}

// Remove the dropdown arrow in Chrome from inputs built with datalists.
// See https://stackoverflow.com/a/54997118

[list]::-webkit-calendar-picker-indicator {
  display: none;
}

// 1. Prevent a WebKit bug where (2) destroys native `audio` and `video`
//    controls in Android 4.
// 2. Correct the inability to style clickable types in iOS and Safari.
// 3. Opinionated: add "hand" cursor to non-disabled button elements.

button,
[type="button"], // 1
[type="reset"],
[type="submit"] {
  -webkit-appearance: button; // 2

  @if $enable-button-pointers {
    &:not(:disabled) {
      cursor: pointer; // 3
    }
  }
}

// Remove inner border and padding from Firefox, but don't restore the outline like Normalize.

::-moz-focus-inner {
  padding: 0;
  border-style: none;
}

// 1. Textareas should really only resize vertically so they don't break their (horizontal) containers.

textarea {
  resize: vertical; // 1
}

// 1. Browsers set a default `min-width: min-content;` on fieldsets,
//    unlike e.g. `<div>`s, which have `min-width: 0;` by default.
//    So we reset that to ensure fieldsets behave more like a standard block element.
//    See https://github.com/twbs/bootstrap/issues/12359
//    and https://html.spec.whatwg.org/multipage/#the-fieldset-and-legend-elements
// 2. Reset the default outline behavior of fieldsets so they don't affect page layout.

fieldset {
  min-width: 0; // 1
  padding: 0; // 2
  margin: 0; // 2
  border: 0; // 2
}

// 1. By using `float: left`, the legend will behave like a block element.
//    This way the border of a fieldset wraps around the legend if present.
// 2. Correct the text wrapping in Edge.
// 3. Fix wrapping bug.
//    See https://github.com/twbs/bootstrap/issues/29712

legend {
  float: left; // 1
  width: 100%;
  padding: 0;
  margin-bottom: $legend-margin-bottom;
  @include font-size($legend-font-size);
  font-weight: $legend-font-weight;
  line-height: inherit;
  white-space: normal; // 2

  + * {
    clear: left; // 3
  }
}

// Fix height of inputs with a type of datetime-local, date, month, week, or time
// See https://github.com/twbs/bootstrap/issues/18842

::-webkit-datetime-edit-fields-wrapper,
::-webkit-datetime-edit-text,
::-webkit-datetime-edit-minute,
::-webkit-datetime-edit-hour-field,
::-webkit-datetime-edit-day-field,
::-webkit-datetime-edit-month-field,
::-webkit-datetime-edit-year-field {
  padding: 0;
}

::-webkit-inner-spin-button {
  height: auto;
}

// 1. Correct the outline style in Safari.
// 2. This overrides the extra rounded corners on search inputs in iOS so that our
//    `.form-control` class can properly style them. Note that this cannot simply
//    be added to `.form-control` as it's not specific enough. For details, see
//    https://github.com/twbs/bootstrap/issues/11586.

[type="search"] {
  outline-offset: -2px; // 1
  -webkit-appearance: textfield; // 2
}

// Remove the inner padding in Chrome and Safari on macOS.

::-webkit-search-decoration {
  -webkit-appearance: none;
}

// Remove padding around color pickers in webkit browsers

::-webkit-color-swatch-wrapper {
  padding: 0;
}

// 1. Change font properties to `inherit` in Safari.
// 2. Correct the inability to style clickable types in iOS and Safari.

::-webkit-file-upload-button {
  font: inherit; // 1
  -webkit-appearance: button; // 2
}

// Correct element displays

output {
  display: inline-block;
}

// Remove border from iframe

iframe {
  border: 0;
}

// Summary
//
// 1. Add the correct display in all browsers

summary {
  display: list-item; // 1
  cursor: pointer;
}

// Progress
//
// Add the correct vertical alignment in Chrome, Firefox, and Opera.

progress {
  vertical-align: baseline;
}

// Hidden attribute
//
// Always hide an element with the `hidden` HTML attribute.

[hidden] {
  display: none !important;
}
